package com.leetcode.algorithm.y22.m07;

/**
 * 299. 猜数字游戏
 * 
 * https://leetcode.cn/problems/bulls-and-cows/
 * 
 * @author jie.deng
 *
 */
class Question0299Solution01 {
	
	public String getHint(String secret, String guess) {
		int[] arrS = new int[10];
		int[] arrG = new int[10];
		int lenS = secret.length();
		int cntA = 0;
		int cntB = 0;
		for (int i = 0; i < lenS; i++) {
			char chS = secret.charAt(i);
			char chG = guess.charAt(i);
			arrS[chS - '0']++;
			arrG[chG - '0']++;
			if (chS == chG) {
				cntA++;
			}
		}
		for (int i = 0; i < 10; i++) {
			cntB += Math.min(arrS[i], arrG[i]);
		}

		cntB -= cntA;
		return String.valueOf(cntA + "A" + cntB + "B");
	}
    
}